const { mongoose } = require('./db')

const Schema = mongoose.Schema

//用户表
const userSchema = new Schema({
    username: String,//用户名
    password: String,//密码
    locking: Boolean,  //是否锁定
    realName: String,//真实姓名
    introduce: String,//介绍
    imgpath: String,//头像
    createTime: {
        type: Date,
        default: new Date()
    },
    role_id: {          // 角色id
        type: mongoose.Types.ObjectId,
        ref: 'role'
    },
    login: Boolean,    //是否限制登录
    superior: String,   //直接上级
    remarks: String, //备注
}, { versionKey: false })

//角色表
const RoleSchema = new Schema({
    roleName: String,
    introduce: String,
    moudule_id: {
        type: mongoose.Types.ObjectId,
        ref: "moudule"
    },
    createTime: {
        type: Date,
        default: new Date()
    },
    content:String,
    menu_id: Array
}, { versionKey: false })

//模块表
const mouduleSchema = new Schema({
    MouduleName: String,
    imgpath: String,//图标
    menu_id: Array
}, { versionKey: false })
//导航栏(权限表)
const menuSchema = new Schema({
    menuName: String,
    menu_key: String,
    parent_id: {
        type: mongoose.Types.ObjectId,
        ref: "menu"
    },
    icon: String,
    desc: Number
}, { versionKey: false })

//部门表
const deparmentSchema = new Schema({
    departentName: String,
    introduce: String,
    parent_id: {
        type: mongoose.Types.ObjectId,
        ref: "department"
    },
    parent: Number,
    jobNumber: String,
    jobName: String,
    jobIfy: String,
}, { versionKey: false })

// 任务表
const taskdata = new Schema({
    taskname: String,
    faname: String,
    tasklevel: String,
    taskstart: String,
    person: String,
    xieperson: String,
    zhiperson: String,
    topdata: Date,
    enddata: Date,
    taskexplain: String,
}, { versionKey: false })

//新闻表
const news = new Schema({
    title: String,
    datetime: Date,
    createuser: {
        type: mongoose.Types.ObjectId,
        ref: "user"
    },
})

//公共表
const noticeSchema = new Schema({
    noticeName: String,
    parent: Number, //级别
    personnel: String, //接收人员
    open: Boolean,  //是否公开
    notice_id: {
        type: mongoose.Types.ObjectId,
        ref: "notice"
    },
    createTime: {
        type: Date,
        default: new Date()
    },
    createuser: {
        type: mongoose.Types.ObjectId,
        ref: "user"
    },
    all: {
        type: mongoose.Types.ObjectId,
        ref: "notice"
    }
}, { versionKey: false })


const userModel = mongoose.model('user', userSchema, 'user')
const roleModel = mongoose.model('role', RoleSchema, 'role')
const mouduleModel = mongoose.model('moudule', mouduleSchema, 'moudule')
const menuModel = mongoose.model('menu', menuSchema, 'menu')
const departModel = mongoose.model('department', deparmentSchema, 'department')
const taskdataModel = mongoose.model('taskdata', taskdata, 'taskdata')
const newsModel = mongoose.model('news', news, 'news')
const noticeModel = mongoose.model('notice', noticeSchema, 'notice')


// userModel.create([{
//     username: 'zhangsan',//用户名
//     password: '123456',//密码
//     locking: false,  //是否锁定
//     realName: '张三',//真实姓名
//     introduce: '',//介绍
//     imgpath: '',//头像
//     createTime: {
//         type: Date,
//         default: new Date()
//     },
//     role_id: {          // 角色id
//         type: mongoose.Types.ObjectId,
//         ref: 'role'
//     },

//     login: Boolean,    //是否限制登录
//     superior: String,   //直接上级
//     remarks: String, //备注
// }, {versionKey: false}])

//角色表
// roleModel.create ([{
//     roleName: String,
//     introduce: String,
//     moudule_id: {
//         type: mongoose.Types.ObjectId,
//         ref: "moudule"
//     },
//     menu_id: Array
// }, {versionKey: false}])


// menuModel.create([{
//     menuName: '客户跟进记录列表',
//     menu_key: '1',
//     parent_id: '63eb00b3c2b5fe08067242c0',
//     icon:'',
//     desc: 1
// }, {versionKey: false}])

// mouduleModel.create([{
//     MouduleName: '销售管理',
//     imgpath: '',//图标
//     menu_id: ['63eb06500c48a90de1819f9a','63eb06500c48a90de1819f9a','63eb0680a6f3d18ae7c64eab','63eb06ad6313dd65cc07b742']
// }, {versionKey: false}])

// mouduleModel.create([{
//     MouduleName: '管理',
//     imgpath: '',//图标
//     menu_id: []
// }, {versionKey: false}])
module.exports = {
    userModel, mouduleModel, roleModel, menuModel, departModel, taskdataModel, newsModel, noticeModel
}